package com.wyg.epgateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Author: WangYongGan
 * @Date: 2022/5/15 12:18
 * @Description:
 */
@Component
public class TestGatewayFilter implements GatewayFilter , Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("过滤");
        final ServerHttpRequest request = exchange.getRequest();
        if(!request.getHeaders().get("token").equals("abc"))
            return chain.filter(exchange);
        return exchange.getResponse().setComplete();
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
